import { load } from "./load";
import { local } from "./local";
import { pool } from "./pool";
import { voice } from "./voice";
import { common } from "../login/common";
import { Sdk_Platform } from "./constants";
import { Login_Status } from "../constants/ui_def";
import { gg } from "./gg";
import { user } from "./user";
import { db } from "./db";


// let he: any = window
// let load1: load = new load()
// he = {
//     load1
// }

export module he {
    export let Load = new load()
    export let Local = new local()
    export let Pool = new pool()
    export let Db = new db()
    export let Voice = new voice()
    export let User = new user()
    export function check_init() {
        console.log('laikai')
        //做成开关
        if (!gg) {
            cc.director.loadScene("Login")
            return true
        }
        return false
    }
    // 初始化sdk
    export function sdkInit() {
        // 此部分再 common.js 部分填写全局配置
        switch (common.sdk_env) {
            // 测试环境
            case Sdk_Platform.VIVO:
                // he.ad = require('./vivoSDK/vivoAd');
                // window.cloud = cc.cloud && cc.cloud.initialize()
                // let auth = cloud.auth();
                // auth.anonymousAuthProvider().signIn().then(res => {
                //     // he.db.init()
                //     he.user.updateManager()
                // });
                break
            case Sdk_Platform.WECHAT:
                // wx.cloud.init({
                //     env: common.env,
                //     traceUser: true
                // })
                // window.cloud = wx.cloud
                // he.ad = require('./wxSDK/wxAd');
                // he.share = require('./wxSDK/wxShare');
                // he.share.onShare()
                // he.user.updateManager()
                // wx.tmSDK.init({
                //     hideRequestLog: false,
                //     appVersion: common.version
                // });
                // 初始化云函数
                break
                // case Sdk_Platform.BYTEDANCE:
                //     he.ad = require('./ttSDK/ttAd');
                // he.log('he.ad',he.ad)
                // console.log("fuck")
                // window.cloud = cc.cloud && cc.cloud.initialize()
                // console.log('字节云', window.cloud)

                // let tt_auth = cloud.auth();
                // tt_auth.anonymousAuthProvider().signIn().then(res => {
                //     he.user.updateManager()
                // });
                // he.user.updateManager()
                break
            case Sdk_Platform.DEBUG:
                // 测试
                if (common.isTest) {
                    he.Db.init()
                } else {
                    // window.cloud = cc.cloud && cc.cloud.initialize()
                    // console.log(cloud)
                    // let auth2 = cloud.auth();
                    // auth2.anonymousAuthProvider().signIn().then(res => {
                    //     he.db.init()
                    // });
                }
                break
        }
        // if (he.ad) {
        //     he.ad.init()
        // }
    }
    // 开关sdk
    export function switchInit() {
        switch (common.sdk_env) {
            // case Sdk_Platform.WECHAT:
            //     let version_info = {}
            //     for (let key in WX_VER_CONFIG) {
            //         version_info[key] = false
            //     }
            //     wx.tmSDK.getAppJSONConfig("shieldArea").then((shieldArea) => {
            //         wx.tmSDK.login().then(login_info => {
            //             if (shieldArea.scene && shieldArea.city && shieldArea.province) {
            //                 if (shieldArea.scene.indexOf(login_info.from_scene) >= 0 ||
            //                     shieldArea.city.indexOf(login_info.login_province) >= 0 ||
            //                     shieldArea.province.indexOf(login_info.login_city) >= 0
            //                 ) {
            //                     he.local.setJson('ver_info', version_info)
            //                     gg.eventManager.emit("login", Login_Status.TO_MAIN)
            //                     return
            //                 }
            //             }
            //             wx.tmSDK.getJudgeConfig().then(res => {
            //                 for (let key in res) {
            //                     let ver_item_info = res[key]
            //                     if (ver_item_info.status) {
            //                         version_info[ver_item_info.key] = true
            //                     } else {
            //                         version_info[ver_item_info.key] = false
            //                     }
            //                 }
            //                 he.local.setJson('ver_info', version_info)
            //                 gg.eventManager.emit("login", Login_Status.TO_MAIN)
            //             }).catch(error => {
            //                 he.local.setJson('ver_info', version_info)
            //                 gg.eventManager.emit("login", Login_Status.TO_MAIN)
            //             })
            //         })
            //     });
            //     break
            case Sdk_Platform.VIVO:
                // gg.eventManager.emit("login", Login_Status.TO_MAIN)
                break
            case Sdk_Platform.OPPO:
                break
            case Sdk_Platform.BYTEDANCE:
                break
            case Sdk_Platform.HUAWEI:
                break
            case Sdk_Platform.DEBUG:
            default:
                cc.director.emit("login", Login_Status.TO_MAIN)
                break
        }
    }
    export function addTip(text) {
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:

                break
            case Sdk_Platform.DEBUG:
                // gg.uiManager.addTip(text)
                break
        }
    }




}
